/**
 * 任务相关路由
 */
const express = require('express');
const router = express.Router();
const taskController = require('../controllers/taskController');
const authenticate = require('../middleware/auth');
const validator = require('../middleware/validator');

// 所有任务路由都需要认证
router.use(authenticate);

// 获取任务列表
router.get('/', taskController.getTasks);

// 获取单个任务
router.get('/:id', validator.validateIdParam(), taskController.getTask);

// 创建任务
router.post(
  '/', 
  validator.validateRequired(['title']),
  validator.validateDates(['start_time', 'end_time', 'reminder_time']),
  taskController.createTask
);

// 更新任务
router.put(
  '/:id', 
  validator.validateIdParam(),
  validator.validateDates(['start_time', 'end_time', 'reminder_time']),
  taskController.updateTask
);

// 删除任务
router.delete('/:id', validator.validateIdParam(), taskController.deleteTask);

// 获取任务分类
router.get('/categories', taskController.getCategories);

// 创建任务分类
router.post(
  '/categories', 
  validator.validateRequired(['name']),
  taskController.createCategory
);

module.exports = router; 